// 不能异步操作
import * as type from './mutations_type.js'
import { currencyRoutes } from '@/router'

// 监听state改变，方法写在vue中的methods中，用commit调用
const mutations = {
  // 设置屏幕字体自适应
  setRem: (state, value) => {
    state.rem = value
  },
  //登录
  [type.LOGIN_IN](state, token) {
    state.token = token;
    localStorage.setItem('userToken', token);
  },
  //设置用户信息
  setUserInfo(state, userInfo) {
    state.userInfo = userInfo;
  },
  // 设置角色
  setRoles(state, roles){
    state.roles = roles
  },
  // 设置路由
  setRoutes(state, payload) {//payload是页面传入的参数
    state.routers = [...currencyRoutes, ...payload]
    state.addRouters = payload
  },
  

  // 商品数据
  reducePrice(state, payload){
    state.data.forEach(item => {
      item.price -= payload;
    });
  },

  //设置当前导航索引
  [type.SET_INDEX](state,data){  
    state.nowIndex = data
    localStorage.setItem("nowIndex",JSON.stringify(state.nowIndex));
  },

  //退出
  [type.LOGIN_OUT](state, token) {
    localStorage.removeItem("userToken", token);
    state.token = token;
  },
}

export default mutations